#pragma once

#include <string>

namespace solution_091
{

class Solution
{
public:
    int numDecodings(std::string s)
    {
        if (s.front() == '0')
            return 0;
        int last_ways_2 = 1;
        int last_ways_1 = 1;
        for (size_t i = 1; i < s.size() && last_ways_1 != 0; ++i) {
            int code = s.at(i) - '0';
            int ways = (code != 0) ? last_ways_1 : 0;
            code += (s.at(i - 1) - '0') * 10;
            ways += (code >= 1 && code <= 26) ? last_ways_2 : 0;
            last_ways_2 = (s.at(i) == '0') ? 0 : last_ways_1;
            last_ways_1 = ways;
        }
        return last_ways_1;
    }
};

}  /* namespace solution_091 */
